package simple;

import java.util.Scanner;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 用数组模拟实现队列-测试类
 * @Date 2024-03-31
 */
public class ArrayQueueTest {

    public static void main(String[] args) {
        ArrayQueueRealize queue = new ArrayQueueRealize(3);

        // 接收用户输入
        char key = ' ';
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;

        // 输出一个菜单
        while (loop) {
            System.out.println("s(show): 显示队列");
            System.out.println("e(exit): 退出程序");
            System.out.println("a(add): 添加数据到队列");
            System.out.println("g(get): 从队列取出数据");
            System.out.println("h(head): 查看队列头的数据");
            // 接收一个字符
            key = scanner.next().charAt(0);
            switch (key) {
                case 's' -> queue.showQueue();
                // 存数据
                case 'a' -> {
                    System.out.println("输出一个数");
                    int value = scanner.nextInt();
                    queue.addQueue(value);
                }
                // 取数据
                case 'g' -> {
                    try {
                        int res = queue.getQueue();
                        System.out.printf("取出的数据是%d\n", res);
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                }
                // 查看队列头的数据
                case 'h' -> {
                    try {
                        int res = queue.headQueue();
                        System.out.printf("队列头的数据是%d\n", res);
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                }
                // 退出
                case 'e' -> {
                    scanner.close();
                    loop = false;
                }
            }
        }

        System.out.println("程序退出~~");
    }
}
